﻿#include "ScrollSpeedWidget.h"
#include "ui_ScrollSpeedWidget.h"
#include "SpeedWidget.h"
#include <QHBoxLayout>

ScrollSpeedWidget::ScrollSpeedWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ScrollSpeedWidget)
{
    ui->setupUi(this);


}

ScrollSpeedWidget::~ScrollSpeedWidget()
{
    delete ui;
}

void ScrollSpeedWidget::setGroupIDAndSensor(int iID, const QList<Sensor> &listSensor, int &maxValue)
{
    QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
    horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
    horizontalLayout->setContentsMargins(40, 0, 40, 0);
    horizontalLayout->setSpacing(40);

    for (int i = 0; i < listSensor.size(); ++i)
    {
        const Sensor& ss = listSensor[i];
        QString strName = QString("%1%2").arg(iID).arg(ss.cell_code);

        SpeedWidget *pSpeed = new SpeedWidget(this);
        pSpeed->setSpeedName(strName);
        pSpeed->setSpeedValue(ss.data);
        pSpeed->setSpeedStatus(ss.status);
        pSpeed->setFixedWidth(90);
        horizontalLayout->addWidget(pSpeed);
        _vecSpeedWidget.push_back(pSpeed);
        if (ss.data > maxValue)
        {
            maxValue = ss.data;
        }
    }

    horizontalLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
}

void ScrollSpeedWidget::setMaxValue(int maxValue)
{
    foreach(auto pIter , _vecSpeedWidget)
    {
        pIter->setMaxValue(maxValue);
    }
}
